package com.yydm.serviceedu.controller;

import com.yydm.commonutils.R;
import com.yydm.serviceedu.service.VodService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * @Classname VodController
 * @Description TODO
 * @Version 1.0.0
 * @Date 2022/6/28 20:54
 * @Created by liu25
 */
@RestController
@RequestMapping("/vod/video")
//@CrossOrigin
public class VodController {

    @Autowired
    private VodService vodService;

    //  上传视频到阿里云
    @ApiOperation(value = "视频上传")
    @PostMapping("/uploadVideo")
    public R uploadVideo(MultipartFile file) {
//        返回上传Id
        String videoId = vodService.uploadVideo(file);

        return R.ok().message("视频上传成功").data("videoId", videoId);
    }


    //    删除阿里云的视频
    @DeleteMapping("/removeVideo/{videoId}")
//               @ApiParam name参数名称 value参数描述 required参数是否必须传递
    public R removeVideo(@ApiParam(name = "videoId", value = "云端视频ID", required = false)
                         @PathVariable String videoId) {
//        删除云端视频方法
        vodService.removeVideo(videoId);

        return R.ok().message("视频删除成功");
    }


}
